home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 012 / keystat.arc / KEYSTAT.DOC < prev   
Encoding:
Text File  |  1986-04-14  |  10.6 KB  |  198 lines

  1.  
  2.        This routine is a resident keyboard interrupt interceptor which displays
  3.        the status of the Capslock and Numlock keys.  If Capslock is on, a "C"
  4.        will be displayed in the upper right hand corner of the display.
  5.        Similarly, a "N" signifies the Numlock mode.
  6.  
  7.             The display is updated after each keystroke.  That is, if you
  8.        install KEYSTAT with capslock on, nothing will be displayed until
  9.        AFTER you strike a key (for more details, see below).
  10.  
  11.        To use the program, type
  12.             KEYSTAT ON
  13.        to install the program or
  14.             KEYSTAT OFF
  15.        to cancel it.  To display the current state, type
  16.             KEYSTAT
  17.        The command syntax is patterned after the DOS BREAK command.
  18.  
  19.        This program requires DOS 2.0 or later.  If loaded on a pre-DOS 2.0 system,
  20.        an error message is displayed.
  21.  
  22.        This routine is called each time a key is pressed.  It will remain resident
  23.        until the system is rebooted or cancelled via the OFF command.  Note, however,
  24.        that the memory allocated to the program when it is installed is NOT freed
  25.        when the routine is turned OFF.  The resident portion of the program takes
  26.        about 650 or so bytes of memory although the operable portion of the program
  27.        (that is, the code that is executed each time a key is pressed) is around
  28.        150 bytes; the available memory reported by CHKDSK, etc... is decreased when
  29.        KEYSTAT is loaded.  Turning KEYSTAT ON, then OFF, then ON again will load another
  30.        copy of the program into memory, decreasing the available memory even further.
  31.        This should not be a problem unless you do this twenty or thirty times.
  32.  
  33.        KEYSTAT simply inserts itself "in series" behind the existing interrupt handler
  34.        and thus SHOULD be compatible with other keyboard utilities such as PROKEY,
  35.        etc... as long as they follow the IBM coding guidelines.  Other programs
  36.        may or may not be compatible with KEYSTAT.  I do not have any of these other
  37.        programs, so there is no way for me to test KEYSTAT with them.  Let me know
  38.        if you have problems using other programs with KEYSTAT.
  39.  
  40.        This program is adapted from an aritcle in October '83 PC-World Magazine,
  41.        page 267.  The author of the original version, called KEYFLAGS, is Morton
  42.        Kaplon.  I found KEYFLAGS to be extremely userful and, as an excercise,
  43.        decided to write my own version.  In the process, I ended
  44.        up adding a few enhancements and changed the name to KEYSTAT.
  45.  
  46.        Here is a summary of the differences between KEYFLAGS and KEYSTAT:
  47.           1. All absolute references to BIOS in KEYFLAGS are replaced by
  48.              interrupts in KEYSTATS.
  49.           2. When KEYSTATS is loaded, it checks to see if it was already
  50.              resident.  KEYFLAGS resets the vector every time, thus allowing
  51.              nesting the code several levels deep.  This was unnecessary since
  52.              the display need only be update once for every keystroke.  Additionally,
  53.              it was undesireable since it would often hang the system.
  54.           3. KEYFLAGS assumed that BIOS was servicing INT 9 and thus
  55.              precluded using PROKEY, etc... with it.  KEYSTAT makes no such
  56.              assumptions.  The previous keyboard service routine, be it BIOS, PROKEY,
  57.              or whatever, is saved and that routine is re-installed when
  58.              KEYSTAT is turned OFF.
  59.           4. Because KEYSTAT uses the new DOS INT 35h, it requires DOS 2.0.
  60.              There is no real reason why this could not be changed to get the
  61.              current interrupt vector directly from memory so that any DOS version
  62.              could be used, but it makes the code a little cleaner.  KEYFLAG can
  63.              be used with any existing version of DOS but compatibility with
  64.              future release is questionable.  KEYSTAT should be compatible with
  65.              future releases of DOS.
  66.           5. KEYFLAGS uses the "@" symbol to signify caps state and the "#" for
  67.              numlock state.  I found these rather cryptic and changed them to
  68.              "C" and "N", respectively in KEYSTAT.
  69.           6. As mentioned earlier, I added command line parameters in KEYSTAT to
  70.              allow for turning the routine OFF and to make it easy to use.
  71.           7. A bug in KEYFLAGS has been fixed in KEYSTAT.  The bug occurs when
  72.              the program is resetting the vector for INT 9.  Should an interrupt
  73.              occur while the vector is being reset, the system will go off into
  74.              computer "never-never land" the next time you press a key.  KEYSTAT
  75.              disables interrupts while this critical section of code is executed.
  76.              Admittedly, this is a rare bug in actual occurence, but it is still
  77.              a bug.
  78.  
  79.        You may make and distribute as many copies of this program as you wish.
  80.        Feel free to modify, mutilate, or adulterate this program.  If you come
  81.        up with an bug or improvement, please let me know by writing me at this
  82.        address:
  83.                Tony A. Rhea
  84.                1030 Ivy Lane
  85.                Cary, NC  27511
  86.        If you do modify it, please give both myself and the original author
  87.        (Morton Kaplon) credit in the program.  This helps to preserve our egos
  88.        and increase our fame (but, unfortunately, NOT our fortunes).  Also, I
  89.        would appreciate a copy of the modified version, preferably on disk (I'll
  90.        be happy to return your diskette).
  91.  
  92.        If you like this program ( or HATE it ), please let me know.  Drop me
  93.        a line at the address given above.
  94.  
  95.        This program has been submitted for publication in PC-WORLD magazine.
  96.  
  97.        I have experimented with an extension of this routine which also displays
  98.        the INSERT and SCROLL-LOCK states as well but found that it caused too much
  99.        overhead -- one could easily "outtype" the system.  Using DOS function 2
  100.        to automatically advance the cursor could eliminate the necessity of moving
  101.        the cursor thru INT 10h since the cursor is automatically advanced when
  102.        the character is displayed.  However, the current display attribute is
  103.        used so the status characters don't stand out very well.  Using DOS function
  104.        9 and printing all the status characters at once from a (constructed) string
  105.        would also work and would allow specifying an "attribute" to use (see the
  106.        discussion of "Extended Screen and Keyboard Control" in chapter 13 of the
  107.        DOS 2.0 manual).  However, that attribute will still be in effect after
  108.        the status characters are displayed.
  109.  
  110.        The initialization code is overlaid by the next program DOS loads so that
  111.        only the ego statement, some variables, and the operable code remain resident.
  112.  
  113.        The video positions are fixed (but can be changed in the equates below)
  114.        and thus will wipe out anything another program puts there.  It is best
  115.        not to put these at the bottom of the screen because the characters would
  116.        be scrolled up.  Putting them at the top of the screen solves this problem.
  117.  
  118.        KEYSTAT waits until BIOS (or whoever) has serviced the keyboard interrupt
  119.        before it updates the display.  This is because it uses the KB_FLAG that
  120.        BIOS (or it's predecessor) must update.  If the user presses the Capslock key,
  121.        KEYSTAT lets the flag be updated first and then gets the flag to sense the
  122.        keyboard status.  If KEYSTAT had updated the display before letting the
  123.        original interrupt servicer update the flag, the display would not be correct
  124.        until the NEXT key is pressed.
  125.  
  126.        Note that INT 25h CANNOT be used for setting a vector permanently.  When your
  127.        program terminates, DOS resets any vectors your program changes.  The only
  128.        way to make the change permanent is by a direct move into the vector table.
  129.  
  130.        I have made heavy use of macros in KEYSTAT -- I find that it enhances the
  131.        readability greatly.  The code is not anything fancy nor is it particuarly
  132.        good, but it works.  This was my first big assembler program (by big I mean
  133.        anything over 10 lines long).  KEYSTAT is a pieced together from code fragments
  134.        from KEYFLAGS and other book and magazine articles.  Therefore, if you find
  135.        that I pushed CS/restored DS when I didn't really need to, it is certainly
  136.        because of my lack of understanding the deeper truths of assembler.  Please
  137.        feel free to improve upon KEYSTAT in any way you see fit.
  138.  
  139.        Pseudocode:
  140.  
  141.          if not(DOS 2.0) then
  142.             error message
  143.             exit
  144.          else
  145.             { we have 2.0 - decode parm }
  146.             get command line parameter
  147.             convert to uppercase
  148.             if (null parameter) then
  149.                { display current status }
  150.                if (already installed) then
  151.                   on message
  152.                else
  153.                   off message
  154.                endif already installed
  155.             else
  156.                { we got a parameter - see if it matches ON }
  157.                if (ON) then
  158.                   if (already resident) then
  159.                      on message
  160.                      exit
  161.                   else
  162.                      make resident
  163.                      on message
  164.                      terminate, leaving operable code resident
  165.                   endif already resident
  166.               else
  167.                   { command wasn't ON -- is it OFF? }
  168.                   if (OFF) then
  169.                      if not(already installed) then
  170.                          off message
  171.                          exit
  172.                      else
  173.                         reset keyboard vector to original servicer
  174.                         off message
  175.                         exit
  176.                      endif not already installed
  177.                   else
  178.                      { we got a command that wasn't OFF or ON }
  179.                      error message
  180.                      exit
  181.                   endif off
  182.                endif on
  183.             endif null parameter
  184.          endif not dos 2.0
  185.  
  186.  
  187.          Revision history:
  188.             rev 1.0  10/15/83                         { original release }
  189.             rev 1.1  10/29/83                         { speed improvement }
  190.  
  191.  
  192.        Copyright (C) 1983  Tony Alan Rhea
  193.        This program may be copied and distributed for personal use
  194.        but not for profit provided this notice is included.  Author makes
  195.        no warranty, expressed or implied, as to the correct nature and
  196.        operation of this software.
  197. d.  Author makes
  198.        no warranty, ex